package com.loy;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

public class ActivitiDemo {

    /**
     * 1. 测试流程部署
     */
    @Test
    public void testDeploment(){
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
        // 使用 repositoryService 进行流程部署，流程部署其实就是将我们刚刚生成的 evection.bpmn.xml 以及 evection.png 放入到数据库中
        // 在执行流程部署的时候，需要指定（1）当前流程的名称。（2）然后把 evection.bpmn.xml 以及 evection.png 放入到数据库中
        Deployment deployment = repositoryService.createDeployment().name("出差申请流程")
                .addClasspathResource("bpmn/evection.bpmn")
                .addClasspathResource("bpmn/evection.png")
                .deploy();
        System.out.println("流程部署id = " +deployment.getId() );
        System.out.println("流程部署名称 = " +deployment.getName() );
    }


    /**
     * 2. 启动流程
     */
    @Test
    public void startProcess(){
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();
        ProcessInstance instance = runtimeService.startProcessInstanceByKey("evection");
        System.out.println("流程定义id = " + instance.getProcessDefinitionId());
        System.out.println("流程实例id = " + instance.getId());
        System.out.println("当前活动id = " + instance.getActivityId());
    }
}
